#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QCompleter>
#include <QStandardItemModel>
#include <QRegularExpression>
#include <QMainWindow>

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

struct PKGInfo : public QObject
{
private:
    Q_OBJECT
public:
    enum Status {
        NOTINSTALLED,
        CONFIGFILES,
        HALFINSTALLED,
        UNPACKED,
        HALFCONFIGURED,
        TRIGGERSAWAITED,
        TRIGGERSPENDING,
        INSTALLED,
    };

    QString name;
    QString version;
    QString desc;
    QStringList cves;
    Status status;
    QString changelogfile;

    PKGInfo(const QString &name = QString(), const QString &version = QString(), const QString &desc = QString(), PKGInfo::Status status = PKGInfo::Status::NOTINSTALLED, const QStringList &cves = QStringList(), QObject *parent = nullptr);
    PKGInfo(const PKGInfo &info, QObject *parent = nullptr);
    PKGInfo &operator=(const PKGInfo &info);
private:
    PKGInfo &copy(const PKGInfo &info);
};
Q_DECLARE_METATYPE(PKGInfo);

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    const QByteArray GZipUncompress(const QByteArray &src);
    const QByteArray LoadChangelog(const PKGInfo &package);
    const QStringList GetPackageCVEs(const PKGInfo &package);
    void UpdatePackages();
    void UpdateUiDatas(bool onlycve = false);

public Q_SLOTS:
    void On_OnlyShowCVE_Toggled(bool checked);
    void On_ComboboxIndex_Changed(int index);
    void On_Table_Clicked(const QModelIndex &index);
    void On_Table_DoubleClicked(const QModelIndex &index);

private:
    Ui::MainWindow *ui;
    QStandardItemModel *m_model_combo;
    QStandardItemModel *m_model_table;
    QCompleter *m_completer;
    int ui_max_widht_name;
    int ui_max_widht_version;
    QString m_combo_current_text;

    QRegularExpression m_re;
    QList<PKGInfo> m_packages;
};
#endif // MAINWINDOW_H
